Welcome![Sign In][Sign Up]
Location:
Search - 3d mesh

Search list

[DirextXMultiAnimation

Description: MultiAnimation  Sample这个例子展示了使用高级shader语言、蒙皮技术和D3DX动画控制器的多动画集的Mesh动画。动画控制器用来混合动画集,以确保从一个动画到另一个动画的平滑转换。<IMG onmouseover=\"if(this.title) {this.style.cursor=hand }\" onclick=\"if(this.title) {window.open(http://msdn.microsoft.com/library/en-us/directx9_c/Sample_MultiAnimation_small.jpg) }\" src=\"http://msdn.microsoft.com/library/en-us/directx9_c/Sample_MultiAnimation_small.jpg\" onload=\"if(this.width>screen.width-333) {this.width=screen.width-333 this.title=open new window }\" border=0 >Path源代码:  (SDK  root)\\Samples\\C++\\Direct3D\\MultiAnimation  可执行文件:  (SDK  root)\\Samples\\C++\\Direct3D\\Bin\\x86  or  x64\\MultiAnimation.exe  Overview这个例子展示如何利用D3DX动画支持,在应用程序中渲染3D动画。D3DX的API函数处理动画Mesh的装载,混合多个动画。动画控制器的功能是支持动画轨,允许从一个动画到另一个动画的平滑转换。这个例子分为2部分:动画类库和应用程序。动画类库是一个多用途库,逻辑上它在应用程序与D3DX之间。为后面的
Platform: | Size: 688490 | Author: 林庆富 | Hits:

[Other resourcepeople_skin

Description: 用于3d游戏动画部分,要求安装有directx9.0 SDK.给mesh贴图时要用,因为是封装完好的引擎,直接可以用.
Platform: | Size: 4144 | Author: 高倩文 | Hits:

[Otherplane0

Description: 这个一个3D游戏源码,实现装入mesh,并渲染以及矩阵相乘
Platform: | Size: 231620 | Author: 李春锃 | Hits:

[Other resourcestone

Description: 3ds file format library.autodesk的官方读写3ds的库.文档俱全(各种函数均有详细的介绍),是读3ds的超级好库.(可以读取3ds中的mesh信息,动画信息,light信息等等,一应俱全啊)-3ds file format library.autodesk official literacy 3d s libraries. Documentation is complete (all functions are described in detail) Reading 3 ds is a super good library. (3 ds can read the information mesh, animation information, light information, etc., in place ah)
Platform: | Size: 79239 | Author: 某某某 | Hits:

[Other resourcePhysXTriangleMesh

Description: Ageia s PhysX(著名的游戏物理库) D3D 9使用代码演示。由于PhysX物理库使用OpenGL代码实现图形着色,从而使许多用DirectX 3D的程序员不能使用/读懂demo代码,这是使用D3D着色引擎重新写的一些demo代码。-Triangle Mesh(带执行文件)
Platform: | Size: 239194 | Author: GoldenCloud | Hits:

[Internet-Network用D3D模拟地月系

Description:

 

 

 

  一、建立空窗体

  新建一个工程,添加引用,并导入名称空间。

  加入一个设备对象变量:

private Microsoft.DirectX.Direct3D.Device device = null;

  添加初始化图形函数,并在这里面对设备对象进行实例化:

public void InitializeGraphics()
{
 PresentParameters presentParams = new PresentParameters();
 presentParams.Windowed = true;
 presentParams.SwapEffect = SwapEffect.Flip;
 presentParams.AutoDepthStencilFormat = DepthFormat.D16;
 presentParams.EnableAutoDepthStencil = true;
 device = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this,  CreateFlags.HardwareVertexProcessing, presentParams);
}

  当程序执行时,需要绘制场景,代码在这个函数里:

public void Render()

{
 // 清空设备,并准备显示下一帧。
 device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black , 1.0f, 0);
 // 设置照相机的位置
 SetupCamera();
 //开始场景
 device.BeginScene();
 if(meshLoaded)
 {
  mesh.Render(meshLoc);
 }
 device.EndScene();
 //显示设备内容。
 device.Present();
}

  设置照相机的位置:

private void SetupCamera()
{
 device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 1000.00f);
 device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f ,0.0f, 20.0f), new Vector3(0.0f,0.0f, 0.0f), new Vector3(0,1,0));
}

  现在改变主函数,调用我们写的初始化函数,并显示场景:

[STAThread]

static void Main()
{
 using (Form1 EarthForm = new Form1())
 {
  EarthForm.InitializeGraphics();
  EarthForm.Show();

  while(EarthForm.Created)
  {
   EarthForm.Render();
   Application.DoEvents();
  }
  EarthForm.Dispose();
}

  运行程序,会显示一个空的窗体。

  二、加入地球:

  在这一步里需创建一个3D网格对象,来作为要显示的地球,为此,在工程中新加入一个类Earth,此类可以包含所创建的网格对象的信息。

  加入一些相关变量,含义见注释:

public class Earth : BaseEarth
{
 private Material[] mMaterials; //保存材质
 private Texture[] mTextures; //保存纹理
 private Matrix locationOffset; //用来保存网格对象的相对位置
 private Mesh mMesh = null; //三角形网格对象
 private Device meshDevice; //需要显示在哪个设备上。
}

  在构造函数中,把Device设备拷贝到私有成员变量,这样就可以在这个类的其它方法内使用它,另外就是把位置变量进行赋值:

public Earth(ref Device device, Matrix location): base(ref device)
{
 meshDevice = device;
 locationOffset = location;
}

  下面这个函数是装入.X文件。

public bool LoadMesh(string meshfile)
{
 ExtendedMaterial[] mtrl;
 try
 {
  // 装载文件
  mMesh = Mesh.FromFile(meshfile, MeshFlags.Managed, meshDevice, out mtrl);
  // 如果有材质的话,装入它们
  if ((mtrl != null) && (mtrl.Length > 0))
  {
   mMaterials = new Material[mtrl.Length];
   mTextures = new Texture[mtrl.Length];

   // 得到材质和纹理

   for (int i = 0; i < mtrl.Length; i++)
   {
    mMaterials[i] = mtrl[i].Material3D;
    if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))

 

    {
     //前面得到的纹理的路径是相对路径,需要保存的是绝对路径,通过应用程序路径可以获得
     mTextures[i] = TextureLoader.FromFile(meshDevice, @"..\..\" + mtrl[i].TextureFilename);
    }
   }
  }
  return true;
 }
 catch
 {
  return false;
 }
}

  在这个方法内,使用Mesh.FromFile()这个方法,从给定的文件名中找到.X文件,并装入相关数据,一旦数据格式设置完成,可以从此文件中找到材质和贴图信息,并把它存放在数组中,并通过文件路径,得到纹理文件文件的路径,最后返回真值,如果整个过程出现错误,返回假值。

  下面这个Render()方法,是把此对象,即地球显示在设备对象上,此方法较简单,通过变形操作来得到网格对象的X,Y,Z坐标,接着设置网格对象的材质和纹理,最后,将每个材质和纹理应用到每个网格。

public void Render(Matrix worldTransform)
{
 /把位置变为世界坐标
 meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
 //绘制网格
 for (int i = 0; i < mMaterials.Length; i++)
 {
  meshDevice.Material = mMaterials[i];
  meshDevice.SetTexture(0, mTextures[i]);
  mMesh.DrawSubset(i);
 }
}

  现在回到窗体代码中,添加引用网格对象的相关变量:

private Earth mesh = null;
private Matrix meshLoc;
private bool meshLoaded = false;

  在图形初始化函数中,需要对网格对象进行初始化。加入下面的代码:

meshLoc = Matrix.Identity;
meshLoc.M41 = 2.0f;
mesh = new Earth(ref device, meshLoc);
if (mesh.LoadMesh(@"..\..\earth.x"))
{
 meshLoaded = true;
}

  代码第一句把网格对象的位置定为原点,接着偏移X轴2个单位,接下来从文件中得到此.X文件。如果成功设置,meshLoaded置为真。注意,这里有一个.X文件,在源代码中有此文件。

 


  在设置相机的函数中,加入一盏灯光:

device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.White;
device.Lights[0].Direction = new Vector3(0, -1, -1);
device.Lights[0].Update();
device.Lights[0].Enabled = true;


  此灯光较简单,仅为一个直射型白光灯。

最后,在Render()方法中,调用网格对象的Render()方法,以显示地球。

 

  三、使地球旋转

  前面用一个网格对象来建立地球,但此类没有平移,旋转及缩放等方法,下面就加入这些方法,因为这些方法具有通用性,因此可以新建一个类,把这些方法写在这些类中,使地球对象成为它的派生类。

  在工程中新添加一个类:BaseEarth;

  加入进行平移、旋转、缩放的变量:

 

private float xloc = 0.0f;
private float yloc = 0.0f;
private float zloc = 0.0f;
private float xrot = 0.0f;
private float yrot = 0.0f;
private float zrot = 0.0f;
private float xscale = 1.0f;
private float yscale = 1.0f;
private float zscale = 1.0f;


  加入相应的属性代码:

 

public float XLoc
{
 get
 {
  return xloc;
 }
 set
 {
  xloc = value;
 }
}
…………

 

  在Render()虚函数中,应用平移、旋转及缩放。
 

public virtual void Render()
{
 objdevice.MultiplyTransform(TransformType.World,Matrix.Translation(xloc, yloc, zloc));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(1.0f, 0.0f, 0.0f), xrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 1.0f, 0.0f), yrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 0.0f, 1.0f), zrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.Scaling(xscale, yscale, zscale));
 return;
}

 

  现在回到地球类,需要将其改为新类的派生类,同时更改构造函数,另外,在Render()方法中,应先调用基类的Render()方法:


public override void Render()
{
 base.Render();
 //把位置变为世界坐标
 // meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
 //绘制网格
 。。。。。。
}

 


  现在,由于在基类中可以设置对象位置,因此,可以把与locationOffset相关,即与设置位置的变量及语句注释掉。

  四、加入月球

  在这一步加入月球,实际上是再创建一个网格对象新实例,只是把纹理进行更改即可,为了代码模块性更好,把两个对象放在一个新类CModel中,在工程中新添加一个类CModel,并声明对象实例。


public class cModel
{
 private cMeshObject mesh1 = null;
 private cMeshObject mesh2 = null;
 private bool modelloaded;
}


  把窗口代码中的Load()事件,放在CModel中,这次不仅生成了地球,而且生成了月球。

 


public void Load(ref Device device)
{
 mesh1 = new Earth(ref device);
 mesh2 = new Earth(ref device);
 if (mesh1.LoadMesh(@"..\..\earth2.x"))
 {
  modelloaded = true;
 }
 else
 {
  modelloaded = false;
 }
 if (mesh2.LoadMesh(@"..\..\moon.x"))
 {
  mesh2.XLoc += 20.0f;
  modelloaded = true;
 }
 else
 {
  modelloaded = false;
 }
}

 

  下面的Update()方法中,参数dir 用来判断是顺时针旋转还是逆时针旋转,另外,地球和月球绕Y轴增加的角度大小不同,也就决定了二者旋转的速度不同。


public void Update(int dir)
{
 if(dir > 0)
 {
  mesh1.YRot += 0.02f;
  mesh2.YRot += 0.05f;
 }
 else if(dir < 0)
 {
  mesh1.YRot -= 0.02f;
  mesh2.YRot -= 0.05f;
 }
}


  在下面的render()方法中,生成显示月球和地球:

 


public void Render(ref Device device)
{
 device.Transform.World = Matrix.Identity;
 if(modelloaded)
 {
  mesh1.Render();
  mesh2.Render();
 }
}


  把窗口代码中的加入灯光的方法,也放在此类中:


public void LoadLights(ref Device device)
{
 device.Lights[0].Type = LightType.Directional;
 device.Lights[0].Diffuse = Color.White;
 device.Lights[0].Position = new Vector3(0.0f, 0.0f, 25.0f);
 device.Lights[0].Direction = new Vector3(0, 0, -1);
}
public void Light(ref Device device)
{
 device.Lights[0].Update();
 device.Lights[0].Enabled = true;
}


  五、与鼠标交互操作

  为了实现与键盘、鼠标交互,新添加一个类:CMouse,添加引用Microsoft.DirectX.DirectInput,并添加命名空间。加入相关变量:


private Microsoft.DirectX.DirectInput.Device mouse = null;
public System.Threading.AutoResetEvent MouseUpdated;
private float x, y, z = 0.0f;
private byte[] buttons;

 

  在下面的构造函数代码中,首先创建鼠标设备,并初始化回调事件:


public CMouse(System.Windows.Forms.Control control)
{
 mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
 mouse.SetCooperativeLevel(control, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
 mouse.Properties.AxisModeAbsolute = false;
 MouseUpdated = new System.Threading.AutoResetEvent(false);
 mouse.SetEventNotification(MouseUpdated);
 mouse.Acquire();
 Update();

 


  下面的Update()方法中获得鼠标的坐标值,并赋给私有成员变量:

public void Update()
{
 MouseState state = mouse.CurrentMouseState;
 x = state.X;
 y = state.Y;
 z = state.Z;
 buttons = state.GetMouseButtons();
}


  还需要有一个函数来检测鼠标左键是否按下:

 


public bool LeftButtonDown
{
 get
 {
  bool a;
  return a = (buttons[0] != 0);
 }
}


  六、大结局

  现在已经做完了准备工作,返回到窗口代码中,需要对这里的代码重新进行一些调整:

  在图形初始化函数中创建一个CModel类及CMouse类:

 

private CModel model = null;
private CMouse mouse = null;
private bool leftbuttondown = false;
private float mousexloc;

 

  添加对鼠标初始化的方法:

 

网管联盟bitsCN@com


public void InitializeInput()
{
 mouse = new CMouse(this);
}


  添加UpdateInputState()方法,当按下鼠标左键时,将leftbuttondown值设置为真,当鼠标抬起时,将mousexloc置0:


private void UpdateInputState()
{
 mouse.Update();
 if (mouse.LeftButtonDown)
 {
  if(leftbuttondown == false)
  {
   mousexloc = 0.0f;
   leftbuttondown = true;
  }
  else
  {
   mousexloc = -mouse.X;
  }
 }
 else
 {
  leftbuttondown = false;
  mousexloc = 0.0f;
 }
}


  在此程序中,只对X值进行了操作,即只能左右转。

  Render()方法更新如下:

public void Render()
{
 UpdateInputState();
 device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkGray, 1.0f, 0);
 SetupCamera();
 device.BeginScene();
 model.Update((int)mousexloc);
 model.Light(ref device);
 model.Render(ref device);
 device.EndScene();
 device.Present();
}

 

  最后更改Main()主函数:


static void Main()
{
 using (Form1 EarthForm = new Form1())
 {
  EarthForm.InitializeGraphics();
  EarthForm.InitializeInput();
  EarthForm.Show();
  while(EarthForm.Created)
  {
   EarthForm.Render();
   Application.DoEvents();
  }
  EarthForm.Dispose();
 }
 


Platform: | Size: 11817 | Author: mantoutou | Hits:

[Windows Developd3dwave

Description: 动态的3d网格画图-dynamic mesh drawing
Platform: | Size: 5120 | Author: 冯吉 | Hits:

[Game Programtank3d

Description: 基于java的3D坦克游戏,第一人称射击视角,内含多边形生成模块,网格模块,实体碰撞的具体演示-based java 3D tank game, the first-person shooter perspective, consisted of polygons generated modules, mesh module, the specific entities collision demo
Platform: | Size: 86016 | Author: 丁中明 | Hits:

[J2MEJSR184Picking

Description: 3D手机开发环境JSR184(M3G)下对于拾取操作的例子,pick技术可以用于拾取场景中的Mesh和Sprite3D,在速度允许的前提下,该技术可作为碰撞检测的一种手段.包含了源代码和简单说明,是学习3D手机开发的好资料.-3D handset development environment JSR184 (M3G) for the picking operation example, pick Technology can be used to pick up the scene and Mesh Sprite3D. speed allowed in under the premise that the technology can be used as a collision detection means. includes source code and explain briefly. 3 D study is the development of good cell phone information.
Platform: | Size: 32768 | Author: gongjian | Hits:

[DirextXD3Dmesh

Description: 关于介绍directx中网络模型的例子.可以读取.x文件,适合初学者学习-for the presentation of directx network model example. Can read. X documents for beginners learning
Platform: | Size: 2628608 | Author: 曹钰 | Hits:

[Graph program3dmesh

Description:
Platform: | Size: 60416 | Author: matengbo | Hits:

[Otherplane0

Description: 这个一个3D游戏源码,实现装入mesh,并渲染以及矩阵相乘-The source of a 3D game, realize load mesh, and rendering as well as matrices
Platform: | Size: 4637696 | Author: 李春锃 | Hits:

[3D GraphicTRI_MESH_TO_PLY

Description: 将三角网格表示的3D曲面转换成一个PLY格式的文件-a MATLAB program which converts data describing a triangular mesh of a 3D surface, and reformats it into a data structure suitable for storage as a PLY file
Platform: | Size: 14336 | Author: niuxj | Hits:

[JSP/Java3.14

Description: java 3d基于三角网格曲面做出的圆柱.请大家参考学习!-java 3d triangular mesh based on the cylindrical surface to make. please refer to learning!
Platform: | Size: 5120 | Author: 黄艳 | Hits:

[Windows Develop3DProgrammingforWindows

Description: 3D Programming for Windows® : Three-Dimensional Graphics Programming for the Windows Presentation Foundation-The Windows Presentation Foundation is a key component of .NET Framework 3.0, which is a part of Windows Vista and available for Windows XP. With the Windows Presentation Foundation, 3D images can be displayed regardless of the video-display hardware on the users machine. Focusing on developing user interface objects or simple animations, this book builds on a readers knowledge of Windows Presentation Foundation essentials to demonstrate how to effectively create 3D graphics for Windows. You get the fundamental information for using the Windows Presentation Foundation 3D application programming interface (API), as well as in-depth coverage of mesh geometries.
Platform: | Size: 3191808 | Author: AKR | Hits:

[J2MEJSR-184

Description: 用jsr184编写的手机3d编程实例,用户可以任意旋转箭头,放大缩小等等。包含如何使用数据定义mesh,如何操作camera如何旋转等等,程序功能较繁杂,但是界面较粗糙(数据定义的模型当然是越简单越好啦),学习意义大于实用意义。-a jsr 184 sample of j2me 3d development, very detail and usefull!
Platform: | Size: 13312 | Author: rp | Hits:

[3D Graphicgmeshsdk

Description: The mesh sdk (gmeshsdk) is a useful geometry library for manipulating 3D meshes and geometry data. It is currently being used on a variety of graphics projects including real-time graphics viewers, 3D paint systems, visualizing complex 3D datasets, and optimizing graphics hardware performance.
Platform: | Size: 116736 | Author: Intentioner | Hits:

[DirextXENG3D

Description: 基于D3D9.0 SDK 尝试制作的3D demo ./DXD3D 简易的D3D 引擎,封装了部分常用工具类,比如蒙皮动画和静态骨骼等等 ./res 资源 ./Textures 资源 ./bin 编译后的程序,以及必须的dll和资源,资源同上级目录,可直接运行(可能需DX9.0 runtime)-D3D9.0 SDK-based production of 3D demo ./DXD3D Simple D3D engine, include some of the common util classes, such as skinned mesh and static mesh, etc. ./res Resources. . ./Textures Resources. ./Bin compiled program, and necessary dll and resources, the resources are the same as what exists in the parent directory. It can be run directly. (DX9.0 runtime maybe necessary)
Platform: | Size: 7578624 | Author: zihao | Hits:

[3D GraphicDreiD

Description: 可以描述图形三维体的演示,网格划分,未完成!有待改进-Can describe the demo, 3d graphics mesh, unfinished! To be improved
Platform: | Size: 2048 | Author: 王鹏 | Hits:

[3D Graphicsmooth_mesh

Description: 读入3d海豚模型并生成平滑网格及渲染的程序-3d dolphin read and generate a smooth mesh model and the rendering process
Platform: | Size: 2453504 | Author: 邓卫民 | Hits:
« 1 2 3 4 5 6 7 89 10 11 »

CodeBus www.codebus.net